home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / etc / mono / 1.0 / DefaultWsdlHelpGenerator.aspx next >
Encoding:
Text File  |  2007-02-27  |  56.4 KB  |  1,807 lines

  1. <%--
  2. //
  3. // DefaultWsdlHelpGenerator.aspx: 
  4. //
  5. // Author:
  6. //   Lluis Sanchez Gual (lluis@ximian.com)
  7. //
  8. // (C) 2003 Ximian, Inc.  http://www.ximian.com
  9. //
  10. --%>
  11.  
  12. <%@ Import Namespace="System.Collections" %>
  13. <%@ Import Namespace="System.IO" %>
  14. <%@ Import Namespace="System.Xml.Serialization" %>
  15. <%@ Import Namespace="System.Xml" %>
  16. <%@ Import Namespace="System.Xml.Schema" %>
  17. <%@ Import Namespace="System.Web.Services.Description" %>
  18. <%@ Import Namespace="System" %>
  19. <%@ Import Namespace="System.Net" %>
  20. <%@ Import Namespace="System.Globalization" %>
  21. <%@ Import Namespace="System.Resources" %>
  22. <%@ Import Namespace="System.Diagnostics" %>
  23. <%@ Import Namespace="System.CodeDom" %>
  24. <%@ Import Namespace="System.CodeDom.Compiler" %>
  25. <%@ Import Namespace="Microsoft.CSharp" %>
  26. <%@ Import Namespace="Microsoft.VisualBasic" %>
  27. <%@ Import Namespace="System.Text.RegularExpressions" %>
  28. <%@ Import Namespace="System.Security.Cryptography.X509Certificates" %>
  29. <%@ Assembly name="System.Web.Services" %>
  30. <%@ Page debug="true" %>
  31.  
  32. <html>
  33. <script language="C#" runat="server">
  34.  
  35. ServiceDescriptionCollection descriptions;
  36. XmlSchemas schemas;
  37.  
  38. string WebServiceName;
  39. string WebServiceDescription;
  40. string PageName;
  41.  
  42. string DefaultBinding;
  43. ArrayList ServiceProtocols;
  44.  
  45. string CurrentOperationName;
  46. string CurrentOperationBinding;
  47. string OperationDocumentation;
  48. string CurrentOperationFormat;
  49. bool CurrentOperationSupportsTest;
  50. ArrayList InParams;
  51. ArrayList OutParams;
  52. string CurrentOperationProtocols;
  53. int CodeTextColumns = 95;
  54.  
  55. void Page_Load(object sender, EventArgs e)
  56. {
  57.     descriptions = (ServiceDescriptionCollection) Context.Items["wsdls"];
  58.     schemas = (XmlSchemas) Context.Items["schemas"];
  59.  
  60.     ServiceDescription desc = descriptions [0];
  61.     if (schemas.Count == 0) schemas = desc.Types.Schemas;
  62.     
  63.     Service service = desc.Services[0];
  64.     WebServiceName = service.Name;
  65.     if (desc.Bindings.Count == 0)
  66.         return;
  67.     
  68.     DefaultBinding = desc.Bindings[0].Name;
  69.     WebServiceDescription = service.Documentation;
  70.     ServiceProtocols = FindServiceProtocols (null);
  71.     
  72.     CurrentOperationName = Request.QueryString["op"];
  73.     CurrentOperationBinding = Request.QueryString["bnd"];
  74.     if (CurrentOperationName != null) BuildOperationInfo ();
  75.  
  76.     PageName = HttpUtility.UrlEncode (Path.GetFileName(Request.Path), Encoding.UTF8);
  77.  
  78.     ArrayList list = new ArrayList ();
  79.     foreach (ServiceDescription sd in descriptions) {
  80.         foreach (Binding bin in sd.Bindings)
  81.             if (bin.Extensions.Find (typeof(SoapBinding)) != null) list.Add (bin);
  82.     }
  83.  
  84.     BindingsRepeater.DataSource = list;
  85.     Page.DataBind();
  86. }
  87.  
  88. void BuildOperationInfo ()
  89. {
  90.     InParams = new ArrayList ();
  91.     OutParams = new ArrayList ();
  92.     
  93.     Port port = FindPort (CurrentOperationBinding, null);
  94.     Binding binding = descriptions.GetBinding (port.Binding);
  95.     
  96.     PortType portType = descriptions.GetPortType (binding.Type);
  97.     Operation oper = FindOperation (portType, CurrentOperationName);
  98.     
  99.     OperationDocumentation = oper.Documentation;
  100.     if (OperationDocumentation == null || OperationDocumentation == "")
  101.         OperationDocumentation = "No additional remarks";
  102.     
  103.     foreach (OperationMessage opm in oper.Messages)
  104.     {
  105.         if (opm is OperationInput)
  106.             BuildParameters (InParams, opm);
  107.         else if (opm is OperationOutput)
  108.             BuildParameters (OutParams, opm);
  109.     }
  110.     
  111.     // Protocols supported by the operation
  112.     CurrentOperationProtocols = "";
  113.     ArrayList prots = FindServiceProtocols (CurrentOperationName);
  114.     for (int n=0; n<prots.Count; n++) {
  115.         if (n != 0) CurrentOperationProtocols += ", ";
  116.         CurrentOperationProtocols += (string) prots[n];
  117.     }
  118.     
  119.     CurrentOperationSupportsTest = prots.Contains ("HttpGet") || prots.Contains ("HttpPost");
  120.  
  121.     // Operation format
  122.     OperationBinding obin = FindOperation (binding, CurrentOperationName);
  123.     if (obin != null)
  124.         CurrentOperationFormat = GetOperationFormat (obin);
  125.  
  126.     InputParamsRepeater.DataSource = InParams;
  127.     InputFormParamsRepeater.DataSource = InParams;
  128.     OutputParamsRepeater.DataSource = OutParams;
  129. }
  130.  
  131. void BuildParameters (ArrayList list, OperationMessage opm)
  132. {
  133.     Message msg = descriptions.GetMessage (opm.Message);
  134.     if (msg.Parts.Count > 0 && msg.Parts[0].Name == "parameters")
  135.     {
  136.         MessagePart part = msg.Parts[0];
  137.         XmlSchemaComplexType ctype;
  138.         if (part.Element == XmlQualifiedName.Empty)
  139.         {
  140.             ctype = (XmlSchemaComplexType) schemas.Find (part.Type, typeof(XmlSchemaComplexType));
  141.         }
  142.         else
  143.         {
  144.             XmlSchemaElement elem = (XmlSchemaElement) schemas.Find (part.Element, typeof(XmlSchemaElement));
  145.             ctype = (XmlSchemaComplexType) elem.SchemaType;
  146.         }
  147.         XmlSchemaSequence seq = ctype.Particle as XmlSchemaSequence;
  148.         if (seq == null) return;
  149.         
  150.         foreach (XmlSchemaObject ob in seq.Items)
  151.         {
  152.             Parameter p = new Parameter();
  153.             p.Description = "No additional remarks";
  154.             
  155.             if (ob is XmlSchemaElement)
  156.             {
  157.                 XmlSchemaElement selem = GetRefElement ((XmlSchemaElement)ob);
  158.                 p.Name = selem.Name;
  159.                 p.Type = selem.SchemaTypeName.Name;
  160.             }
  161.             else
  162.             {
  163.                 p.Name = "Unknown";
  164.                 p.Type = "Unknown";
  165.             }
  166.             list.Add (p);
  167.         }
  168.     }
  169.     else
  170.     {
  171.         foreach (MessagePart part in msg.Parts)
  172.         {
  173.             Parameter p = new Parameter ();
  174.             p.Description = "No additional remarks";
  175.             p.Name = part.Name;
  176.             if (part.Element == XmlQualifiedName.Empty)
  177.                 p.Type = part.Type.Name;
  178.             else
  179.             {
  180.                 XmlSchemaElement elem = (XmlSchemaElement) schemas.Find (part.Element, typeof(XmlSchemaElement));
  181.                 p.Type = elem.SchemaTypeName.Name;
  182.             }
  183.             list.Add (p);
  184.         }
  185.     }
  186. }
  187.  
  188. string GetOperationFormat (OperationBinding obin)
  189. {
  190.     string format = "";
  191.     SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
  192.     if (sob != null) {
  193.         format = sob.Style.ToString ();
  194.         SoapBodyBinding sbb = obin.Input.Extensions.Find (typeof(SoapBodyBinding)) as SoapBodyBinding;
  195.         if (sbb != null)
  196.             format += " / " + sbb.Use;
  197.     }
  198.     return format;
  199. }
  200.  
  201. XmlSchemaElement GetRefElement (XmlSchemaElement elem)
  202. {
  203.     if (!elem.RefName.IsEmpty)
  204.         return (XmlSchemaElement) schemas.Find (elem.RefName, typeof(XmlSchemaElement));
  205.     else
  206.         return elem;
  207. }
  208.  
  209. ArrayList FindServiceProtocols(string operName)
  210. {
  211.     ArrayList table = new ArrayList ();
  212.     Service service = descriptions[0].Services[0];
  213.     foreach (Port port in service.Ports)
  214.     {
  215.         string prot = null;
  216.         Binding bin = descriptions.GetBinding (port.Binding);
  217.         if (bin.Extensions.Find (typeof(SoapBinding)) != null)
  218.             prot = "Soap";
  219.         else 
  220.         {
  221.             HttpBinding hb = (HttpBinding) bin.Extensions.Find (typeof(HttpBinding));
  222.             if (hb != null && hb.Verb == "POST") prot = "HttpPost";
  223.             else if (hb != null && hb.Verb == "GET") prot = "HttpGet";
  224.         }
  225.         
  226.         if (prot != null && operName != null)
  227.         {
  228.             if (FindOperation (bin, operName) == null)
  229.                 prot = null;
  230.         }
  231.  
  232.         if (prot != null && !table.Contains (prot))
  233.             table.Add (prot);
  234.     }
  235.     return table;
  236. }
  237.  
  238. Port FindPort (string portName, string protocol)
  239. {
  240.     Service service = descriptions[0].Services[0];
  241.     foreach (Port port in service.Ports)
  242.     {
  243.         if (portName == null)
  244.         {
  245.             Binding binding = descriptions.GetBinding (port.Binding);
  246.             if (GetProtocol (binding) == protocol) return port;
  247.         }
  248.         else if (port.Name == portName)
  249.             return port;
  250.     }
  251.     return null;
  252. }
  253.  
  254. string GetProtocol (Binding binding)
  255. {
  256.     if (binding.Extensions.Find (typeof(SoapBinding)) != null) return "Soap";
  257.     HttpBinding hb = (HttpBinding) binding.Extensions.Find (typeof(HttpBinding));
  258.     if (hb == null) return "";
  259.     if (hb.Verb == "POST") return "HttpPost";
  260.     if (hb.Verb == "GET") return "HttpGet";
  261.     return "";
  262. }
  263.  
  264.  
  265. Operation FindOperation (PortType portType, string name)
  266. {
  267.     foreach (Operation oper in portType.Operations) {
  268.         if (oper.Messages.Input.Name != null) {
  269.             if (oper.Messages.Input.Name == name) return oper;
  270.         }
  271.         else
  272.             if (oper.Name == name) return oper;
  273.     }
  274.         
  275.     return null;
  276. }
  277.  
  278. OperationBinding FindOperation (Binding binding, string name)
  279. {
  280.     foreach (OperationBinding oper in binding.Operations) {
  281.         if (oper.Input.Name != null) {
  282.             if (oper.Input.Name == name) return oper;
  283.         }
  284.         else 
  285.             if (oper.Name == name) return oper;
  286.     }
  287.         
  288.     return null;
  289. }
  290.  
  291. string FormatBindingName (string name)
  292. {
  293.     if (name == DefaultBinding) return "Methods";
  294.     else return "Methods for binding<br>" + name;
  295. }
  296.  
  297. string GetOpName (object op)
  298. {
  299.     OperationBinding ob = op as OperationBinding;
  300.     if (ob == null) return "";
  301.     if (ob.Input.Name != null) return ob.Input.Name;
  302.     else return ob.Name;
  303. }
  304.  
  305. bool HasFormResult
  306. {
  307.     get { return Request.QueryString ["ext"] == "testform"; }
  308. }
  309.  
  310. class NoCheckCertificatePolicy : ICertificatePolicy {
  311.     public bool CheckValidationResult (ServicePoint a, X509Certificate b, WebRequest c, int d)
  312.     {
  313.         return true;
  314.     }
  315. }
  316.  
  317. string GetTestResult ()
  318.     if (!HasFormResult) return null;
  319.     
  320.     bool fill = false;
  321.     string qs = "";
  322.     for (int n=0; n<Request.QueryString.Count; n++)
  323.     {
  324.         if (fill) {
  325.             if (qs != "") qs += "&";
  326.             qs += Request.QueryString.GetKey(n) + "=" + Server.UrlEncode (Request.QueryString [n]);
  327.         }
  328.         if (Request.QueryString.GetKey(n) == "ext") fill = true;
  329.     }
  330.         
  331.     string location = null;
  332.     ServiceDescription desc = descriptions [0];
  333.     Service service = desc.Services[0];
  334.     foreach (Port port in service.Ports)
  335.         if (port.Name == CurrentOperationBinding)
  336.         {
  337.             SoapAddressBinding sbi = (SoapAddressBinding) port.Extensions.Find (typeof(SoapAddressBinding));
  338.             if (sbi != null)
  339.                 location = sbi.Location;
  340.         }
  341.  
  342.     if (location == null) 
  343.         return "Could not locate web service";
  344.     
  345.     try
  346.     {
  347.         string url = location + "/" + CurrentOperationName;
  348.         Uri uri = new Uri (url);
  349.         HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url + "?" + qs);
  350.         if (url.StartsWith ("https:"))
  351.             ServicePointManager.CertificatePolicy = new NoCheckCertificatePolicy ();
  352.         HttpCookieCollection cookies = Request.Cookies;
  353.         int last = cookies.Count;
  354.         if (last > 0) {
  355.             CookieContainer container = new CookieContainer ();
  356.             for (int i = 0; i < last; i++) {
  357.                 HttpCookie hcookie = cookies [i];
  358.                 Cookie cookie = new Cookie (hcookie.Name, hcookie.Value, hcookie.Path, hcookie.Domain);
  359.                 container.Add (uri, cookie);
  360.             }
  361.             ((HttpWebRequest) req).CookieContainer = container;
  362.         }
  363.         WebResponse resp = req.GetResponse();
  364.         StreamReader sr = new StreamReader (resp.GetResponseStream());
  365.         string s = sr.ReadToEnd ();
  366.         sr.Close ();
  367.         return "<div class='code-xml'>" + ColorizeXml(WrapText(s,CodeTextColumns)) + "</div>";
  368.     }
  369.     catch (Exception ex)
  370.     { 
  371.         string res = "<b style='color:red'>" + ex.Message + "</b>";
  372.         WebException wex = ex as WebException;
  373.         if (wex != null)
  374.         {
  375.             WebResponse resp = wex.Response;
  376.             if (resp != null) {
  377.                 StreamReader sr = new StreamReader (resp.GetResponseStream());
  378.                 string s = sr.ReadToEnd ();
  379.                 sr.Close ();
  380.                 res += "<div class='code-xml'>" + ColorizeXml(WrapText(s,CodeTextColumns)) + "</div>";
  381.             }
  382.         }
  383.         return res;
  384.     }
  385. }
  386.  
  387. string GenerateOperationMessages (string protocol, bool generateInput)
  388. {
  389.     if (!IsOperationSupported (protocol)) return "";
  390.     
  391.     Port port;
  392.     if (protocol != "Soap") port = FindPort (null, protocol);
  393.     else port = FindPort (CurrentOperationBinding, null);
  394.     
  395.     Binding binding = descriptions.GetBinding (port.Binding);
  396.     OperationBinding obin = FindOperation (binding, CurrentOperationName);
  397.     PortType portType = descriptions.GetPortType (binding.Type);
  398.     Operation oper = FindOperation (portType, CurrentOperationName);
  399.     
  400.     HtmlSampleGenerator sg = new HtmlSampleGenerator (descriptions, schemas);
  401.     string txt = sg.GenerateMessage (port, obin, oper, protocol, generateInput);
  402.     if (protocol == "Soap") txt = WrapText (txt,CodeTextColumns);
  403.     txt = ColorizeXml (txt);
  404.     txt = txt.Replace ("@placeholder!","<span class='literal-placeholder'>");
  405.     txt = txt.Replace ("!placeholder@","</span>");
  406.     return txt;
  407. }
  408.  
  409. bool IsOperationSupported (string protocol)
  410. {
  411.     if (CurrentPage != "op" || CurrentTab != "msg") return false;
  412.     if (protocol == "Soap") return true;
  413.  
  414.     Port port = FindPort (null, protocol);
  415.     if (port == null) return false;
  416.     Binding binding = descriptions.GetBinding (port.Binding);
  417.     if (binding == null) return false;
  418.     return FindOperation (binding, CurrentOperationName) != null;
  419. }
  420.  
  421. //
  422. // Proxy code generation
  423. //
  424.  
  425. string GetProxyCode ()
  426. {
  427.     CodeNamespace codeNamespace = new CodeNamespace();
  428.     CodeCompileUnit codeUnit = new CodeCompileUnit();
  429.     
  430.     codeUnit.Namespaces.Add (codeNamespace);
  431.  
  432.     ServiceDescriptionImporter importer = new ServiceDescriptionImporter();
  433.     
  434.     foreach (ServiceDescription sd in descriptions)
  435.         importer.AddServiceDescription(sd, null, null);
  436.  
  437.     foreach (XmlSchema sc in schemas)
  438.         importer.Schemas.Add (sc);
  439.  
  440.     importer.Import(codeNamespace, codeUnit);
  441.  
  442.     string langId = Request.QueryString ["lang"];
  443.     if (langId == null || langId == "") langId = "cs";
  444.     CodeDomProvider provider = GetProvider (langId);
  445.     ICodeGenerator generator = provider.CreateGenerator();
  446.     CodeGeneratorOptions options = new CodeGeneratorOptions();
  447.     
  448.     StringWriter sw = new StringWriter ();
  449.     generator.GenerateCodeFromCompileUnit(codeUnit, sw, options);
  450.  
  451.     return Colorize (WrapText (sw.ToString (), CodeTextColumns), langId);
  452. }
  453.  
  454. public string CurrentLanguage
  455. {
  456.     get {
  457.         string langId = Request.QueryString ["lang"];
  458.         if (langId == null || langId == "") langId = "cs";
  459.         return langId;
  460.     }
  461. }
  462.  
  463. public string CurrentProxytName
  464. {
  465.     get {
  466.         string lan = CurrentLanguage == "cs" ? "C#" : "Visual Basic";
  467.         return lan + " Client Proxy";
  468.     }
  469. }
  470.  
  471. private CodeDomProvider GetProvider(string langId)
  472. {
  473.     switch (langId.ToUpper())
  474.     {
  475.         case "CS": return new CSharpCodeProvider();
  476.         case "VB": return new VBCodeProvider();
  477.         default: return null;
  478.     }
  479. }
  480.  
  481. //
  482. // Document generation
  483. //
  484.  
  485. string GenerateDocument ()
  486. {
  487.     StringWriter sw = new StringWriter ();
  488.     
  489.     if (CurrentDocType == "wsdl")
  490.         descriptions [CurrentDocInd].Write (sw);
  491.     else if (CurrentDocType == "schema")
  492.         schemas [CurrentDocInd].Write (sw);
  493.         
  494.     return Colorize (WrapText (sw.ToString (), CodeTextColumns), "xml");
  495. }
  496.  
  497. public string CurrentDocType
  498. {
  499.     get { return Request.QueryString ["doctype"] != null ? Request.QueryString ["doctype"] : "wsdl"; }
  500. }
  501.  
  502. public int CurrentDocInd
  503. {
  504.     get { return Request.QueryString ["docind"] != null ? int.Parse (Request.QueryString ["docind"]) : 0; }
  505. }
  506.  
  507. public string CurrentDocumentName
  508. {
  509.     get {
  510.         if (CurrentDocType == "wsdl")
  511.             return "WSDL document for namespace \"" + descriptions [CurrentDocInd].TargetNamespace + "\"";
  512.         else
  513.             return "Xml Schema for namespace \"" + schemas [CurrentDocInd].TargetNamespace + "\"";
  514.     }
  515. }
  516.  
  517. //
  518. // Pages and tabs
  519. //
  520.  
  521. bool firstTab = true;
  522. ArrayList disabledTabs = new ArrayList ();
  523.  
  524. string CurrentTab
  525. {
  526.     get { return Request.QueryString["tab"] != null ? Request.QueryString["tab"] : "main" ; }
  527. }
  528.  
  529. string CurrentPage
  530. {
  531.     get { return Request.QueryString["page"] != null ? Request.QueryString["page"] : "main" ; }
  532. }
  533.  
  534. void WriteTabs ()
  535. {
  536.     if (CurrentOperationName != null)
  537.     {
  538.         WriteTab ("main","Overview");
  539.         WriteTab ("test","Test Form");
  540.         WriteTab ("msg","Message Layout");
  541.     }
  542. }
  543.  
  544. void WriteTab (string id, string label)
  545. {
  546.     if (!firstTab) Response.Write(" | ");
  547.     firstTab = false;
  548.     
  549.     string cname = CurrentTab == id ? "tabLabelOn" : "tabLabelOff";
  550.     Response.Write ("<a href='" + PageName + "?" + GetPageContext(null) + GetDataContext() + "tab=" + id + "' style='text-decoration:none'>");
  551.     Response.Write ("<span class='" + cname + "'>" + label + "</span>");
  552.     Response.Write ("</a>");
  553. }
  554.  
  555. string GetTabContext (string pag, string tab)
  556. {
  557.     if (tab == null) tab = CurrentTab;
  558.     if (pag == null) pag = CurrentPage;
  559.     if (pag != CurrentPage) tab = "main";
  560.     return "page=" + pag + "&tab=" + tab + "&"; 
  561. }
  562.  
  563. string GetPageContext (string pag)
  564. {
  565.     if (pag == null) pag = CurrentPage;
  566.     return "page=" + pag + "&"; 
  567. }
  568.  
  569. class Tab
  570. {
  571.     public string Id;
  572.     public string Label;
  573. }
  574.  
  575. //
  576. // Syntax coloring
  577. //
  578.  
  579. static string keywords_cs =
  580.     "(\\babstract\\b|\\bevent\\b|\\bnew\\b|\\bstruct\\b|\\bas\\b|\\bexplicit\\b|\\bnull\\b|\\bswitch\\b|\\bbase\\b|\\bextern\\b|" +
  581.     "\\bobject\\b|\\bthis\\b|\\bbool\\b|\\bfalse\\b|\\boperator\\b|\\bthrow\\b|\\bbreak\\b|\\bfinally\\b|\\bout\\b|\\btrue\\b|" +
  582.     "\\bbyte\\b|\\bfixed\\b|\\boverride\\b|\\btry\\b|\\bcase\\b|\\bfloat\\b|\\bparams\\b|\\btypeof\\b|\\bcatch\\b|\\bfor\\b|" +
  583.     "\\bprivate\\b|\\buint\\b|\\bchar\\b|\\bforeach\\b|\\bprotected\\b|\\bulong\\b|\\bchecked\\b|\\bgoto\\b|\\bpublic\\b|" +
  584.     "\\bunchecked\\b|\\bclass\\b|\\bif\\b|\\breadonly\\b|\\bunsafe\\b|\\bconst\\b|\\bimplicit\\b|\\bref\\b|\\bushort\\b|" +
  585.     "\\bcontinue\\b|\\bin\\b|\\breturn\\b|\\busing\\b|\\bdecimal\\b|\\bint\\b|\\bsbyte\\b|\\bvirtual\\b|\\bdefault\\b|" +
  586.     "\\binterface\\b|\\bsealed\\b|\\bvolatile\\b|\\bdelegate\\b|\\binternal\\b|\\bshort\\b|\\bvoid\\b|\\bdo\\b|\\bis\\b|" +
  587.     "\\bsizeof\\b|\\bwhile\\b|\\bdouble\\b|\\block\\b|\\bstackalloc\\b|\\belse\\b|\\blong\\b|\\bstatic\\b|\\benum\\b|" +
  588.     "\\bnamespace\\b|\\bstring\\b)";
  589.  
  590. static string keywords_vb =
  591.     "(\\bAddHandler\\b|\\bAddressOf\\b|\\bAlias\\b|\\bAnd\\b|\\bAndAlso\\b|\\bAnsi\\b|\\bAs\\b|\\bAssembly\\b|" +
  592.     "\\bAuto\\b|\\bBoolean\\b|\\bByRef\\b|\\bByte\\b|\\bByVal\\b|\\bCall\\b|\\bCase\\b|\\bCatch\\b|" +
  593.     "\\bCBool\\b|\\bCByte\\b|\\bCChar\\b|\\bCDate\\b|\\bCDec\\b|\\bCDbl\\b|\\bChar\\b|\\bCInt\\b|" +
  594.     "\\bClass\\b|\\bCLng\\b|\\bCObj\\b|\\bConst\\b|\\bCShort\\b|\\bCSng\\b|\\bCStr\\b|\\bCType\\b|" +
  595.     "\\bDate\\b|\\bDecimal\\b|\\bDeclare\\b|\\bDefault\\b|\\bDelegate\\b|\\bDim\\b|\\bDirectCast\\b|\\bDo\\b|" +
  596.     "\\bDouble\\b|\\bEach\\b|\\bElse\\b|\\bElseIf\\b|\\bEnd\\b|\\bEnum\\b|\\bErase\\b|\\bError\\b|" +
  597.     "\\bEvent\\b|\\bExit\\b|\\bFalse\\b|\\bFinally\\b|\\bFor\\b|\\bFriend\\b|\\bFunction\\b|\\bGet\\b|" +
  598.     "\\bGetType\\b|\\bGoSub\\b|\\bGoTo\\b|\\bHandles\\b|\\bIf\\b|\\bImplements\\b|\\bImports\\b|\\bIn\\b|" +
  599.     "\\bInherits\\b|\\bInteger\\b|\\bInterface\\b|\\bIs\\b|\\bLet\\b|\\bLib\\b|\\bLike\\b|\\bLong\\b|" +
  600.     "\\bLoop\\b|\\bMe\\b|\\bMod\\b|\\bModule\\b|\\bMustInherit\\b|\\bMustOverride\\b|\\bMyBase\\b|\\bMyClass\\b|" +
  601.     "\\bNamespace\\b|\\bNew\\b|\\bNext\\b|\\bNot\\b|\\bNothing\\b|\\bNotInheritable\\b|\\bNotOverridable\\b|\\bObject\\b|" +
  602.     "\\bOn\\b|\\bOption\\b|\\bOptional\\b|\\bOr\\b|\\bOrElse\\b|\\bOverloads\\b|\\bOverridable\\b|\\bOverrides\\b|" +
  603.     "\\bParamArray\\b|\\bPreserve\\b|\\bPrivate\\b|\\bProperty\\b|\\bProtected\\b|\\bPublic\\b|\\bRaiseEvent\\b|\\bReadOnly\\b|" +
  604.     "\\bReDim\\b|\\bREM\\b|\\bRemoveHandler\\b|\\bResume\\b|\\bReturn\\b|\\bSelect\\b|\\bSet\\b|\\bShadows\\b|" +
  605.     "\\bShared\\b|\\bShort\\b|\\bSingle\\b|\\bStatic\\b|\\bStep\\b|\\bStop\\b|\\bString\\b|\\bStructure\\b|" +
  606.     "\\bSub\\b|\\bSyncLock\\b|\\bThen\\b|\\bThrow\\b|\\bTo\\b|\\bTrue\\b|\\bTry\\b|\\bTypeOf\\b|" +
  607.     "\\bUnicode\\b|\\bUntil\\b|\\bVariant\\b|\\bWhen\\b|\\bWhile\\b|\\bWith\\b|\\bWithEvents\\b|\\bWriteOnly\\b|\\bXor\\b)";
  608.  
  609. string Colorize (string text, string lang)
  610. {
  611.     if (lang == "xml") return ColorizeXml (text);
  612.     else if (lang == "cs") return ColorizeCs (text);
  613.     else if (lang == "vb") return ColorizeVb (text);
  614.     else return text;
  615. }
  616.  
  617. string ColorizeXml (string text)
  618. {
  619.     text = text.Replace (" ", " ");
  620.     Regex re = new Regex ("\r\n|\r|\n");
  621.     text = re.Replace (text, "_br_");
  622.     
  623.     re = new Regex ("<\\s*(\\/?)\\s*([\\s\\S]*?)\\s*(\\/?)\\s*>");
  624.     text = re.Replace (text,"{blue:<$1}{maroon:$2}{blue:$3>}");
  625.     
  626.     re = new Regex ("\\{(\\w*):([\\s\\S]*?)\\}");
  627.     text = re.Replace (text,"<span style='color:$1'>$2</span>");
  628.  
  629.     re = new Regex ("\"(.*?)\"");
  630.     text = re.Replace (text,"\"<span style='color:purple'>$1</span>\"");
  631.  
  632.     
  633.     text = text.Replace ("\t", "     ");
  634.     text = text.Replace ("_br_", "<br>");
  635.     return text;
  636. }
  637.  
  638. string ColorizeCs (string text)
  639. {
  640.     text = text.Replace (" ", " ");
  641.  
  642.     text = text.Replace ("<", "<");
  643.     text = text.Replace (">", ">");
  644.  
  645.     Regex re = new Regex ("\"((((?!\").)|\\\")*?)\"");
  646.     text = re.Replace (text,"<span style='color:purple'>\"$1\"</span>");
  647.  
  648.     re = new Regex ("//(((.(?!\"</span>))|\"(((?!\").)*)\"</span>)*)(\r|\n|\r\n)");
  649.     text = re.Replace (text,"<span style='color:green'>//$1</span><br/>");
  650.     
  651.     re = new Regex (keywords_cs);
  652.     text = re.Replace (text,"<span style='color:blue'>$1</span>");
  653.     
  654.     text = text.Replace ("\t","     ");
  655.     text = text.Replace ("\n","<br/>");
  656.     
  657.     return text;
  658. }
  659.  
  660. string ColorizeVb (string text)
  661. {
  662.     text = text.Replace (" ", " ");
  663.     
  664. /*    Regex re = new Regex ("\"((((?!\").)|\\\")*?)\"");
  665.     text = re.Replace (text,"<span style='color:purple'>\"$1\"</span>");
  666.  
  667.     re = new Regex ("'(((.(?!\"\\<\\/span\\>))|\"(((?!\").)*)\"\\<\\/span\\>)*)(\r|\n|\r\n)");
  668.     text = re.Replace (text,"<span style='color:green'>//$1</span><br/>");
  669.     
  670.     re = new Regex (keywords_vb);
  671.     text = re.Replace (text,"<span style='color:blue'>$1</span>");
  672. */    
  673.     text = text.Replace ("\t","     ");
  674.     text = text.Replace ("\n","<br/>");
  675.     return text;
  676. }
  677.  
  678. //
  679. // Helper methods and classes
  680. //
  681.  
  682. string GetDataContext ()
  683. {
  684.     return "op=" + CurrentOperationName + "&bnd=" + CurrentOperationBinding + "&";
  685. }
  686.  
  687. string GetOptionSel (string v1, string v2)
  688. {
  689.     string op = "<option ";
  690.     if (v1 == v2) op += "selected ";
  691.     return op + "value='" + v1 + "'>";
  692. }
  693.  
  694. string WrapText (string text, int maxChars)
  695. {
  696.     text =  text.Replace(" />","/>");
  697.     
  698.     string linspace = null;
  699.     int lincount = 0;
  700.     int breakpos = 0;
  701.     int linstart = 0;
  702.     bool inquotes = false;
  703.     char lastc = ' ';
  704.     string sublineIndent = "";
  705.     System.Text.StringBuilder sb = new System.Text.StringBuilder ();
  706.     for (int n=0; n<text.Length; n++)
  707.     {
  708.         char c = text [n];
  709.         
  710.         if (c=='\r' || c=='\n' || n==text.Length-1)
  711.         {
  712.             sb.Append (linspace + sublineIndent + text.Substring (linstart, n-linstart+1));
  713.             linspace = null;
  714.             lincount = 0;
  715.             linstart = n+1;
  716.             breakpos = linstart;
  717.             sublineIndent = "";
  718.             lastc = c;
  719.             continue;
  720.         }
  721.         
  722.         if (lastc==',' || lastc=='(')
  723.         {
  724.             if (!inquotes) breakpos = n;
  725.         }
  726.         
  727.         if (lincount > maxChars && breakpos >= linstart)
  728.         {
  729.             if (linspace != null)
  730.                 sb.Append (linspace + sublineIndent);
  731.             sb.Append (text.Substring (linstart, breakpos-linstart));
  732.             sb.Append ("\n");
  733.             sublineIndent = "     ";
  734.             lincount = linspace.Length + sublineIndent.Length + (n-breakpos);
  735.             linstart = breakpos;
  736.         }
  737.         
  738.         if (c==' ' || c=='\t')
  739.         {
  740.             if (!inquotes)
  741.                 breakpos = n;
  742.         }
  743.         else if (c=='"')
  744.         {
  745.             inquotes = !inquotes;
  746.         }
  747.         else 
  748.             if (linspace == null) {
  749.                 linspace = text.Substring (linstart, n-linstart);
  750.                 linstart = n;
  751.             }
  752.  
  753.         lincount++;
  754.         lastc = c;
  755.     }
  756.     return sb.ToString ();
  757. }
  758.  
  759. class Parameter
  760. {
  761.     string name;
  762.     string type;
  763.     string description;
  764.  
  765.     public string Name { get { return name; } set { name = value; } }
  766.     public string Type { get { return type; } set { type = value; } }
  767.     public string Description { get { return description; } set { description = value; } }
  768. }
  769.  
  770. public class HtmlSampleGenerator: SampleGenerator
  771. {
  772.     public HtmlSampleGenerator (ServiceDescriptionCollection services, XmlSchemas schemas)
  773.     : base (services, schemas)
  774.     {
  775.     }
  776.         
  777.     protected override string GetLiteral (string s)
  778.     {
  779.         return "@placeholder!" + s + "!placeholder@";
  780.     }
  781. }
  782.  
  783.  
  784.     public class SampleGenerator
  785.     {
  786.         protected ServiceDescriptionCollection descriptions;
  787.         protected XmlSchemas schemas;
  788.         XmlSchemaElement anyElement;
  789.         ArrayList queue;
  790.         SoapBindingUse currentUse;
  791.         XmlDocument document = new XmlDocument ();
  792.         
  793.         static readonly XmlQualifiedName anyType = new XmlQualifiedName ("anyType",XmlSchema.Namespace);
  794.         static readonly XmlQualifiedName arrayType = new XmlQualifiedName ("Array","http://schemas.xmlsoap.org/soap/encoding/");
  795.         static readonly XmlQualifiedName arrayTypeRefName = new XmlQualifiedName ("arrayType","http://schemas.xmlsoap.org/soap/encoding/");
  796.         const string SoapEnvelopeNamespace = "http://schemas.xmlsoap.org/soap/envelope/";
  797.         const string WsdlNamespace = "http://schemas.xmlsoap.org/wsdl/";
  798.         const string SoapEncodingNamespace = "http://schemas.xmlsoap.org/soap/encoding/";
  799.         
  800.         class EncodedType
  801.         {
  802.             public EncodedType (string ns, XmlSchemaElement elem) { Namespace = ns; Element = elem; }
  803.             public string Namespace;
  804.             public XmlSchemaElement Element;
  805.         }
  806.  
  807.         public SampleGenerator (ServiceDescriptionCollection services, XmlSchemas schemas)
  808.         {
  809.             descriptions = services;
  810.             this.schemas = schemas;
  811.             queue = new ArrayList ();
  812.         }
  813.         
  814.         public string GenerateMessage (Port port, OperationBinding obin, Operation oper, string protocol, bool generateInput)
  815.         {
  816.             OperationMessage msg = null;
  817.             foreach (OperationMessage opm in oper.Messages)
  818.             {
  819.                 if (opm is OperationInput && generateInput) msg = opm;
  820.                 else if (opm is OperationOutput && !generateInput) msg = opm;
  821.             }
  822.             if (msg == null) return null;
  823.             
  824.             switch (protocol) {
  825.                 case "Soap": return GenerateHttpSoapMessage (port, obin, oper, msg);
  826.                 case "HttpGet": return GenerateHttpGetMessage (port, obin, oper, msg);
  827.                 case "HttpPost": return GenerateHttpPostMessage (port, obin, oper, msg);
  828.             }
  829.             return "Unknown protocol";
  830.         }
  831.         
  832.         public string GenerateHttpSoapMessage (Port port, OperationBinding obin, Operation oper, OperationMessage msg)
  833.         {
  834.             string req = "";
  835.             
  836.             if (msg is OperationInput)
  837.             {
  838.                 SoapAddressBinding sab = port.Extensions.Find (typeof(SoapAddressBinding)) as SoapAddressBinding;
  839.                 SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
  840.                 req += "POST " + new Uri (sab.Location).AbsolutePath + "\n";
  841.                 req += "SOAPAction: " + sob.SoapAction + "\n";
  842.                 req += "Content-Type: text/xml; charset=utf-8\n";
  843.                 req += "Content-Length: " + GetLiteral ("string") + "\n";
  844.                 req += "Host: " + GetLiteral ("string") + "\n\n";
  845.             }
  846.             else
  847.             {
  848.                 req += "HTTP/1.0 200 OK\n";
  849.                 req += "Content-Type: text/xml; charset=utf-8\n";
  850.                 req += "Content-Length: " + GetLiteral ("string") + "\n\n";
  851.             }
  852.             
  853.             req += GenerateSoapMessage (obin, oper, msg);
  854.             return req;
  855.         }
  856.         
  857.         public string GenerateHttpGetMessage (Port port, OperationBinding obin, Operation oper, OperationMessage msg)
  858.         {
  859.             string req = "";
  860.             
  861.             if (msg is OperationInput)
  862.             {
  863.                 HttpAddressBinding sab = port.Extensions.Find (typeof(HttpAddressBinding)) as HttpAddressBinding;
  864.                 HttpOperationBinding sob = obin.Extensions.Find (typeof(HttpOperationBinding)) as HttpOperationBinding;
  865.                 string location = new Uri (sab.Location).AbsolutePath + sob.Location + "?" + BuildQueryString (msg);
  866.                 req += "GET " + location + "\n";
  867.                 req += "Host: " + GetLiteral ("string");
  868.             }
  869.             else
  870.             {
  871.                 req += "HTTP/1.0 200 OK\n";
  872.                 req += "Content-Type: text/xml; charset=utf-8\n";
  873.                 req += "Content-Length: " + GetLiteral ("string") + "\n\n";
  874.             
  875.                 MimeXmlBinding mxb = (MimeXmlBinding) obin.Output.Extensions.Find (typeof(MimeXmlBinding)) as MimeXmlBinding;
  876.                 if (mxb == null) return req;
  877.                 
  878.                 Message message = descriptions.GetMessage (msg.Message);
  879.                 XmlQualifiedName ename = null;
  880.                 foreach (MessagePart part in message.Parts)
  881.                     if (part.Name == mxb.Part) ename = part.Element;
  882.                     
  883.                 if (ename == null) return req + GetLiteral("string");
  884.                 
  885.                 StringWriter sw = new StringWriter ();
  886.                 XmlTextWriter xtw = new XmlTextWriter (sw);
  887.                 xtw.Formatting = Formatting.Indented;
  888.                 currentUse = SoapBindingUse.Literal;
  889.                 WriteRootElementSample (xtw, ename);
  890.                 xtw.Close ();
  891.                 req += sw.ToString ();
  892.             }
  893.             
  894.             return req;
  895.         }
  896.         
  897.         public string GenerateHttpPostMessage (Port port, OperationBinding obin, Operation oper, OperationMessage msg)
  898.         {
  899.             string req = "";
  900.             
  901.             if (msg is OperationInput)
  902.             {
  903.                 HttpAddressBinding sab = port.Extensions.Find (typeof(HttpAddressBinding)) as HttpAddressBinding;
  904.                 HttpOperationBinding sob = obin.Extensions.Find (typeof(HttpOperationBinding)) as HttpOperationBinding;
  905.                 string location = new Uri (sab.Location).AbsolutePath + sob.Location;
  906.                 req += "POST " + location + "\n";
  907.                 req += "Content-Type: application/x-www-form-urlencoded\n";
  908.                 req += "Content-Length: " + GetLiteral ("string") + "\n";
  909.                 req += "Host: " + GetLiteral ("string") + "\n\n";
  910.                 req += BuildQueryString (msg);
  911.             }
  912.             else return GenerateHttpGetMessage (port, obin, oper, msg);
  913.             
  914.             return req;
  915.         }
  916.         
  917.         string BuildQueryString (OperationMessage opm)
  918.         {
  919.             string s = "";
  920.             Message msg = descriptions.GetMessage (opm.Message);
  921.             foreach (MessagePart part in msg.Parts)
  922.             {
  923.                 if (s.Length != 0) s += "&";
  924.                 s += part.Name + "=" + GetLiteral (part.Type.Name);
  925.             }
  926.             return s;
  927.         }
  928.         
  929.         public string GenerateSoapMessage (OperationBinding obin, Operation oper, OperationMessage msg)
  930.         {
  931.             SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
  932.             SoapBindingStyle style = (sob != null) ? sob.Style : SoapBindingStyle.Document;
  933.             
  934.             MessageBinding msgbin = (msg is OperationInput) ? (MessageBinding) obin.Input : (MessageBinding)obin.Output;
  935.             SoapBodyBinding sbb = msgbin.Extensions.Find (typeof(SoapBodyBinding)) as SoapBodyBinding;
  936.             SoapBindingUse bodyUse = (sbb != null) ? sbb.Use : SoapBindingUse.Literal;
  937.             
  938.             StringWriter sw = new StringWriter ();
  939.             XmlTextWriter xtw = new XmlTextWriter (sw);
  940.             xtw.Formatting = Formatting.Indented;
  941.             
  942.             xtw.WriteStartDocument ();
  943.             xtw.WriteStartElement ("soap", "Envelope", SoapEnvelopeNamespace);
  944.             xtw.WriteAttributeString ("xmlns", "xsi", null, XmlSchema.InstanceNamespace);
  945.             xtw.WriteAttributeString ("xmlns", "xsd", null, XmlSchema.Namespace);
  946.             
  947.             if (bodyUse == SoapBindingUse.Encoded) 
  948.             {
  949.                 xtw.WriteAttributeString ("xmlns", "soapenc", null, SoapEncodingNamespace);
  950.                 xtw.WriteAttributeString ("xmlns", "tns", null, msg.Message.Namespace);
  951.             }
  952.  
  953.             // Serialize headers
  954.             
  955.             bool writtenHeader = false;
  956.             foreach (object ob in msgbin.Extensions)
  957.             {
  958.                 SoapHeaderBinding hb = ob as SoapHeaderBinding;
  959.                 if (hb == null) continue;
  960.                 
  961.                 if (!writtenHeader) {
  962.                     xtw.WriteStartElement ("soap", "Header", SoapEnvelopeNamespace);
  963.                     writtenHeader = true;
  964.                 }
  965.                 
  966.                 WriteHeader (xtw, hb);
  967.             }
  968.             
  969.             if (writtenHeader)
  970.                 xtw.WriteEndElement ();
  971.  
  972.             // Serialize body
  973.             xtw.WriteStartElement ("soap", "Body", SoapEnvelopeNamespace);
  974.             
  975.             currentUse = bodyUse;
  976.             WriteBody (xtw, oper, msg, sbb, style);
  977.             
  978.             xtw.WriteEndElement ();
  979.             xtw.WriteEndElement ();
  980.             xtw.Close ();
  981.             return sw.ToString ();
  982.         }
  983.         
  984.         void WriteHeader (XmlTextWriter xtw, SoapHeaderBinding header)
  985.         {
  986.             Message msg = descriptions.GetMessage (header.Message);
  987.             if (msg == null) throw new InvalidOperationException ("Message " + header.Message + " not found");
  988.             MessagePart part = msg.Parts [header.Part];
  989.             if (part == null) throw new InvalidOperationException ("Message part " + header.Part + " not found in message " + header.Message);
  990.  
  991.             currentUse = header.Use;
  992.             
  993.             if (currentUse == SoapBindingUse.Literal)
  994.                 WriteRootElementSample (xtw, part.Element);
  995.             else
  996.                 WriteTypeSample (xtw, part.Type);
  997.         }
  998.         
  999.         void WriteBody (XmlTextWriter xtw, Operation oper, OperationMessage opm, SoapBodyBinding sbb, SoapBindingStyle style)
  1000.         {
  1001.             Message msg = descriptions.GetMessage (opm.Message);
  1002.             if (msg.Parts.Count > 0 && msg.Parts[0].Name == "parameters")
  1003.             {
  1004.                 MessagePart part = msg.Parts[0];
  1005.                 if (part.Element == XmlQualifiedName.Empty)
  1006.                     WriteTypeSample (xtw, part.Type);
  1007.                 else
  1008.                     WriteRootElementSample (xtw, part.Element);
  1009.             }
  1010.             else
  1011.             {
  1012.                 string elemName = oper.Name;
  1013.                 string ns = "";
  1014.                 if (opm is OperationOutput) elemName += "Response";
  1015.                 
  1016.                 if (style == SoapBindingStyle.Rpc) {
  1017.                     xtw.WriteStartElement (elemName, sbb.Namespace);
  1018.                     ns = sbb.Namespace;
  1019.                 }
  1020.                     
  1021.                 foreach (MessagePart part in msg.Parts)
  1022.                 {
  1023.                     if (part.Element == XmlQualifiedName.Empty)
  1024.                     {
  1025.                         XmlSchemaElement elem = new XmlSchemaElement ();
  1026.                         elem.SchemaTypeName = part.Type;
  1027.                         elem.Name = part.Name;
  1028.                         WriteElementSample (xtw, ns, elem);
  1029.                     }
  1030.                     else
  1031.                         WriteRootElementSample (xtw, part.Element);
  1032.                 }
  1033.                 
  1034.                 if (style == SoapBindingStyle.Rpc)
  1035.                     xtw.WriteEndElement ();
  1036.             }
  1037.             WriteQueuedTypeSamples (xtw);
  1038.         }
  1039.         
  1040.         void WriteRootElementSample (XmlTextWriter xtw, XmlQualifiedName qname)
  1041.         {
  1042.             XmlSchemaElement elem = (XmlSchemaElement) schemas.Find (qname, typeof(XmlSchemaElement));
  1043.             if (elem == null) throw new InvalidOperationException ("Element not found: " + qname);
  1044.             WriteElementSample (xtw, qname.Namespace, elem);
  1045.         }
  1046.         
  1047.         void WriteElementSample (XmlTextWriter xtw, string ns, XmlSchemaElement elem)
  1048.         {
  1049.             bool sharedAnnType = false;
  1050.             XmlQualifiedName root;
  1051.             
  1052.             if (!elem.RefName.IsEmpty) {
  1053.                 XmlSchemaElement refElem = FindRefElement (elem);
  1054.                 if (refElem == null) throw new InvalidOperationException ("Global element not found: " + elem.RefName);
  1055.                 root = elem.RefName;
  1056.                 elem = refElem;
  1057.                 sharedAnnType = true;
  1058.             }
  1059.             else
  1060.                 root = new XmlQualifiedName (elem.Name, ns);
  1061.             
  1062.             if (!elem.SchemaTypeName.IsEmpty)
  1063.             {
  1064.                 XmlSchemaComplexType st = FindComplexTyype (elem.SchemaTypeName);
  1065.                 if (st != null) 
  1066.                     WriteComplexTypeSample (xtw, st, root);
  1067.                 else
  1068.                 {
  1069.                     xtw.WriteStartElement (root.Name, root.Namespace);
  1070.                     if (currentUse == SoapBindingUse.Encoded) 
  1071.                         xtw.WriteAttributeString ("type", XmlSchema.InstanceNamespace, GetQualifiedNameString (xtw, elem.SchemaTypeName));
  1072.                     xtw.WriteString (GetLiteral (FindBuiltInType (elem.SchemaTypeName)));
  1073.                     xtw.WriteEndElement ();
  1074.                 }
  1075.             }
  1076.             else if (elem.SchemaType == null)
  1077.             {
  1078.                 xtw.WriteStartElement ("any");
  1079.                 xtw.WriteEndElement ();
  1080.             }
  1081.             else
  1082.                 WriteComplexTypeSample (xtw, (XmlSchemaComplexType) elem.SchemaType, root);
  1083.         }
  1084.         
  1085.         void WriteTypeSample (XmlTextWriter xtw, XmlQualifiedName qname)
  1086.         {
  1087.             XmlSchemaComplexType ctype = FindComplexTyype (qname);
  1088.             if (ctype != null) {
  1089.                 WriteComplexTypeSample (xtw, ctype, qname);
  1090.                 return;
  1091.             }
  1092.             
  1093.             XmlSchemaSimpleType stype = (XmlSchemaSimpleType) schemas.Find (qname, typeof(XmlSchemaSimpleType));
  1094.             if (stype != null) {
  1095.                 WriteSimpleTypeSample (xtw, stype);
  1096.                 return;
  1097.             }
  1098.             
  1099.             xtw.WriteString (GetLiteral (FindBuiltInType (qname)));
  1100.             throw new InvalidOperationException ("Type not found: " + qname);
  1101.         }
  1102.         
  1103.         void WriteComplexTypeSample (XmlTextWriter xtw, XmlSchemaComplexType stype, XmlQualifiedName rootName)
  1104.         {
  1105.             WriteComplexTypeSample (xtw, stype, rootName, -1);
  1106.         }
  1107.         
  1108.         void WriteComplexTypeSample (XmlTextWriter xtw, XmlSchemaComplexType stype, XmlQualifiedName rootName, int id)
  1109.         {
  1110.             string ns = rootName.Namespace;
  1111.             
  1112.             if (rootName.Name.IndexOf ("[]") != -1) rootName = arrayType;
  1113.             
  1114.             if (currentUse == SoapBindingUse.Encoded) {
  1115.                 string pref = xtw.LookupPrefix (rootName.Namespace);
  1116.                 if (pref == null) pref = "q1";
  1117.                 xtw.WriteStartElement (pref, rootName.Name, rootName.Namespace);
  1118.                 ns = "";
  1119.             }
  1120.             else
  1121.                 xtw.WriteStartElement (rootName.Name, rootName.Namespace);
  1122.             
  1123.             if (id != -1)
  1124.             {
  1125.                 xtw.WriteAttributeString ("id", "id" + id);
  1126.                 if (rootName != arrayType)
  1127.                     xtw.WriteAttributeString ("type", XmlSchema.InstanceNamespace, GetQualifiedNameString (xtw, rootName));
  1128.             }
  1129.             
  1130.             WriteComplexTypeAttributes (xtw, stype);
  1131.             WriteComplexTypeElements (xtw, ns, stype);
  1132.             
  1133.             xtw.WriteEndElement ();
  1134.         }
  1135.         
  1136.         void WriteComplexTypeAttributes (XmlTextWriter xtw, XmlSchemaComplexType stype)
  1137.         {
  1138.             WriteAttributes (xtw, stype.Attributes, stype.AnyAttribute);
  1139.         }
  1140.         
  1141.         void WriteComplexTypeElements (XmlTextWriter xtw, string ns, XmlSchemaComplexType stype)
  1142.         {
  1143.             if (stype.Particle != null)
  1144.                 WriteParticleComplexContent (xtw, ns, stype.Particle);
  1145.             else
  1146.             {
  1147.                 if (stype.ContentModel is XmlSchemaSimpleContent)
  1148.                     WriteSimpleContent (xtw, (XmlSchemaSimpleContent)stype.ContentModel);
  1149.                 else if (stype.ContentModel is XmlSchemaComplexContent)
  1150.                     WriteComplexContent (xtw, ns, (XmlSchemaComplexContent)stype.ContentModel);
  1151.             }
  1152.         }
  1153.  
  1154.         void WriteAttributes (XmlTextWriter xtw, XmlSchemaObjectCollection atts, XmlSchemaAnyAttribute anyat)
  1155.         {
  1156.             foreach (XmlSchemaObject at in atts)
  1157.             {
  1158.                 if (at is XmlSchemaAttribute)
  1159.                 {
  1160.                     string ns;
  1161.                     XmlSchemaAttribute attr = (XmlSchemaAttribute)at;
  1162.                     XmlSchemaAttribute refAttr = attr;
  1163.                     
  1164.                     // refAttr.Form; TODO
  1165.                     
  1166.                     if (!attr.RefName.IsEmpty) {
  1167.                         refAttr = FindRefAttribute (attr.RefName);
  1168.                         if (refAttr == null) throw new InvalidOperationException ("Global attribute not found: " + attr.RefName);
  1169.                     }
  1170.                     
  1171.                     string val;
  1172.                     if (!refAttr.SchemaTypeName.IsEmpty) val = FindBuiltInType (refAttr.SchemaTypeName);
  1173.                     else val = FindBuiltInType ((XmlSchemaSimpleType) refAttr.SchemaType);
  1174.                     
  1175.                     xtw.WriteAttributeString (refAttr.Name, val);
  1176.                 }
  1177.                 else if (at is XmlSchemaAttributeGroupRef)
  1178.                 {
  1179.                     XmlSchemaAttributeGroupRef gref = (XmlSchemaAttributeGroupRef)at;
  1180.                     XmlSchemaAttributeGroup grp = (XmlSchemaAttributeGroup) schemas.Find (gref.RefName, typeof(XmlSchemaAttributeGroup));
  1181.                     WriteAttributes (xtw, grp.Attributes, grp.AnyAttribute);
  1182.                 }
  1183.             }
  1184.             
  1185.             if (anyat != null)
  1186.                 xtw.WriteAttributeString ("custom-attribute","value");
  1187.         }
  1188.         
  1189.         void WriteParticleComplexContent (XmlTextWriter xtw, string ns, XmlSchemaParticle particle)
  1190.         {
  1191.             WriteParticleContent (xtw, ns, particle, false);
  1192.         }
  1193.         
  1194.         void WriteParticleContent (XmlTextWriter xtw, string ns, XmlSchemaParticle particle, bool multiValue)
  1195.         {
  1196.             if (particle is XmlSchemaGroupRef)
  1197.                 particle = GetRefGroupParticle ((XmlSchemaGroupRef)particle);
  1198.  
  1199.             if (particle.MaxOccurs > 1) multiValue = true;
  1200.             
  1201.             if (particle is XmlSchemaSequence) {
  1202.                 WriteSequenceContent (xtw, ns, ((XmlSchemaSequence)particle).Items, multiValue);
  1203.             }
  1204.             else if (particle is XmlSchemaChoice) {
  1205.                 if (((XmlSchemaChoice)particle).Items.Count == 1)
  1206.                     WriteSequenceContent (xtw, ns, ((XmlSchemaChoice)particle).Items, multiValue);
  1207.                 else
  1208.                     WriteChoiceContent (xtw, ns, (XmlSchemaChoice)particle, multiValue);
  1209.             }
  1210.             else if (particle is XmlSchemaAll) {
  1211.                 WriteSequenceContent (xtw, ns, ((XmlSchemaAll)particle).Items, multiValue);
  1212.             }
  1213.         }
  1214.  
  1215.         void WriteSequenceContent (XmlTextWriter xtw, string ns, XmlSchemaObjectCollection items, bool multiValue)
  1216.         {
  1217.             foreach (XmlSchemaObject item in items)
  1218.                 WriteContentItem (xtw, ns, item, multiValue);
  1219.         }
  1220.         
  1221.         void WriteContentItem (XmlTextWriter xtw, string ns, XmlSchemaObject item, bool multiValue)
  1222.         {
  1223.             if (item is XmlSchemaGroupRef)
  1224.                 item = GetRefGroupParticle ((XmlSchemaGroupRef)item);
  1225.                     
  1226.             if (item is XmlSchemaElement)
  1227.             {
  1228.                 XmlSchemaElement elem = (XmlSchemaElement) item;
  1229.                 XmlSchemaElement refElem;
  1230.                 if (!elem.RefName.IsEmpty) refElem = FindRefElement (elem);
  1231.                 else refElem = elem;
  1232.  
  1233.                 int num = (elem.MaxOccurs == 1 && !multiValue) ? 1 : 2;
  1234.                 for (int n=0; n<num; n++)
  1235.                 {
  1236.                     if (currentUse == SoapBindingUse.Literal)
  1237.                         WriteElementSample (xtw, ns, refElem);
  1238.                     else
  1239.                         WriteRefTypeSample (xtw, ns, refElem);
  1240.                 }
  1241.             }
  1242.             else if (item is XmlSchemaAny)
  1243.             {
  1244.                 xtw.WriteString (GetLiteral ("xml"));
  1245.             }
  1246.             else if (item is XmlSchemaParticle) {
  1247.                 WriteParticleContent (xtw, ns, (XmlSchemaParticle)item, multiValue);
  1248.             }
  1249.         }
  1250.         
  1251.         void WriteChoiceContent (XmlTextWriter xtw, string ns, XmlSchemaChoice choice, bool multiValue)
  1252.         {
  1253.             foreach (XmlSchemaObject item in choice.Items)
  1254.                 WriteContentItem (xtw, ns, item, multiValue);
  1255.         }
  1256.  
  1257.         void WriteSimpleContent (XmlTextWriter xtw, XmlSchemaSimpleContent content)
  1258.         {
  1259.             XmlSchemaSimpleContentExtension ext = content.Content as XmlSchemaSimpleContentExtension;
  1260.             if (ext != null)
  1261.                 WriteAttributes (xtw, ext.Attributes, ext.AnyAttribute);
  1262.                 
  1263.             XmlQualifiedName qname = GetContentBaseType (content.Content);
  1264.             xtw.WriteString (GetLiteral (FindBuiltInType (qname)));
  1265.         }
  1266.  
  1267.         string FindBuiltInType (XmlQualifiedName qname)
  1268.         {
  1269.             if (qname.Namespace == XmlSchema.Namespace)
  1270.                 return qname.Name;
  1271.  
  1272.             XmlSchemaComplexType ct = FindComplexTyype (qname);
  1273.             if (ct != null)
  1274.             {
  1275.                 XmlSchemaSimpleContent sc = ct.ContentModel as XmlSchemaSimpleContent;
  1276.                 if (sc == null) throw new InvalidOperationException ("Invalid schema");
  1277.                 return FindBuiltInType (GetContentBaseType (sc.Content));
  1278.             }
  1279.             
  1280.             XmlSchemaSimpleType st = (XmlSchemaSimpleType) schemas.Find (qname, typeof(XmlSchemaSimpleType));
  1281.             if (st != null)
  1282.                 return FindBuiltInType (st);
  1283.  
  1284.             throw new InvalidOperationException ("Definition of type " + qname + " not found");
  1285.         }
  1286.  
  1287.         string FindBuiltInType (XmlSchemaSimpleType st)
  1288.         {
  1289.             if (st.Content is XmlSchemaSimpleTypeRestriction) {
  1290.                 return FindBuiltInType (GetContentBaseType (st.Content));
  1291.             }
  1292.             else if (st.Content is XmlSchemaSimpleTypeList) {
  1293.                 string s = FindBuiltInType (GetContentBaseType (st.Content));
  1294.                 return s + " " + s + " ...";
  1295.             }
  1296.             else if (st.Content is XmlSchemaSimpleTypeUnion)
  1297.             {
  1298.                 //Check if all types of the union are equal. If not, then will use anyType.
  1299.                 XmlSchemaSimpleTypeUnion uni = (XmlSchemaSimpleTypeUnion) st.Content;
  1300.                 string utype = null;
  1301.  
  1302.                 // Anonymous types are unique
  1303.                 if (uni.BaseTypes.Count != 0 && uni.MemberTypes.Length != 0)
  1304.                     return "string";
  1305.  
  1306.                 foreach (XmlQualifiedName mt in uni.MemberTypes)
  1307.                 {
  1308.                     string qn = FindBuiltInType (mt);
  1309.                     if (utype != null && qn != utype) return "string";
  1310.                     else utype = qn;
  1311.                 }
  1312.                 return utype;
  1313.             }
  1314.             else
  1315.                 return "string";
  1316.         }
  1317.         
  1318.  
  1319.         XmlQualifiedName GetContentBaseType (XmlSchemaObject ob)
  1320.         {
  1321.             if (ob is XmlSchemaSimpleContentExtension)
  1322.                 return ((XmlSchemaSimpleContentExtension)ob).BaseTypeName;
  1323.             else if (ob is XmlSchemaSimpleContentRestriction)
  1324.                 return ((XmlSchemaSimpleContentRestriction)ob).BaseTypeName;
  1325.             else if (ob is XmlSchemaSimpleTypeRestriction)
  1326.                 return ((XmlSchemaSimpleTypeRestriction)ob).BaseTypeName;
  1327.             else if (ob is XmlSchemaSimpleTypeList)
  1328.                 return ((XmlSchemaSimpleTypeList)ob).ItemTypeName;
  1329.             else
  1330.                 return null;
  1331.         }
  1332.  
  1333.         void WriteComplexContent (XmlTextWriter xtw, string ns, XmlSchemaComplexContent content)
  1334.         {
  1335.             XmlQualifiedName qname;
  1336.  
  1337.             XmlSchemaComplexContentExtension ext = content.Content as XmlSchemaComplexContentExtension;
  1338.             if (ext != null) qname = ext.BaseTypeName;
  1339.             else {
  1340.                 XmlSchemaComplexContentRestriction rest = (XmlSchemaComplexContentRestriction)content.Content;
  1341.                 qname = rest.BaseTypeName;
  1342.                 if (qname == arrayType) {
  1343.                     ParseArrayType (rest, out qname);
  1344.                     XmlSchemaElement elem = new XmlSchemaElement ();
  1345.                     elem.Name = "Item";
  1346.                     elem.SchemaTypeName = qname;
  1347.                     
  1348.                     xtw.WriteAttributeString ("arrayType", SoapEncodingNamespace, qname.Name + "[2]");
  1349.                     WriteContentItem (xtw, ns, elem, true);
  1350.                     return;
  1351.                 }
  1352.             }
  1353.             
  1354.             // Add base map members to this map
  1355.             XmlSchemaComplexType ctype = FindComplexTyype (qname);
  1356.             WriteComplexTypeAttributes (xtw, ctype);
  1357.             
  1358.             if (ext != null) {
  1359.                 // Add the members of this map
  1360.                 WriteAttributes (xtw, ext.Attributes, ext.AnyAttribute);
  1361.                 if (ext.Particle != null)
  1362.                     WriteParticleComplexContent (xtw, ns, ext.Particle);
  1363.             }
  1364.             
  1365.             WriteComplexTypeElements (xtw, ns, ctype);
  1366.         }
  1367.         
  1368.         void ParseArrayType (XmlSchemaComplexContentRestriction rest, out XmlQualifiedName qtype)
  1369.         {
  1370.             XmlSchemaAttribute arrayTypeAt = FindArrayAttribute (rest.Attributes);
  1371.             XmlAttribute[] uatts = arrayTypeAt.UnhandledAttributes;
  1372.             if (uatts == null || uatts.Length == 0) throw new InvalidOperationException ("arrayType attribute not specified in array declaration");
  1373.             
  1374.             XmlAttribute xat = null;
  1375.             foreach (XmlAttribute at in uatts)
  1376.                 if (at.LocalName == "arrayType" && at.NamespaceURI == WsdlNamespace)
  1377.                     { xat = at; break; }
  1378.             
  1379.             if (xat == null) 
  1380.                 throw new InvalidOperationException ("arrayType attribute not specified in array declaration");
  1381.             
  1382.             string arrayType = xat.Value;
  1383.             string type, ns;
  1384.             int i = arrayType.LastIndexOf (":");
  1385.             if (i == -1) ns = "";
  1386.             else ns = arrayType.Substring (0,i);
  1387.             
  1388.             int j = arrayType.IndexOf ("[", i+1);
  1389.             if (j == -1) throw new InvalidOperationException ("Cannot parse WSDL array type: " + arrayType);
  1390.             type = arrayType.Substring (i+1);
  1391.             type = type.Substring (0, type.Length-2);
  1392.             
  1393.             qtype = new XmlQualifiedName (type, ns);
  1394.         }
  1395.         
  1396.         XmlSchemaAttribute FindArrayAttribute (XmlSchemaObjectCollection atts)
  1397.         {
  1398.             foreach (object ob in atts)
  1399.             {
  1400.                 XmlSchemaAttribute att = ob as XmlSchemaAttribute;
  1401.                 if (att != null && att.RefName == arrayTypeRefName) return att;
  1402.                 
  1403.                 XmlSchemaAttributeGroupRef gref = ob as XmlSchemaAttributeGroupRef;
  1404.                 if (gref != null)
  1405.                 {
  1406.                     XmlSchemaAttributeGroup grp = (XmlSchemaAttributeGroup) schemas.Find (gref.RefName, typeof(XmlSchemaAttributeGroup));
  1407.                     att = FindArrayAttribute (grp.Attributes);
  1408.                     if (att != null) return att;
  1409.                 }
  1410.             }
  1411.             return null;
  1412.         }
  1413.         
  1414.         void WriteSimpleTypeSample (XmlTextWriter xtw, XmlSchemaSimpleType stype)
  1415.         {
  1416.             xtw.WriteString (GetLiteral (FindBuiltInType (stype)));
  1417.         }
  1418.         
  1419.         XmlSchemaParticle GetRefGroupParticle (XmlSchemaGroupRef refGroup)
  1420.         {
  1421.             XmlSchemaGroup grp = (XmlSchemaGroup) schemas.Find (refGroup.RefName, typeof (XmlSchemaGroup));
  1422.             return grp.Particle;
  1423.         }
  1424.  
  1425.         XmlSchemaElement FindRefElement (XmlSchemaElement elem)
  1426.         {
  1427.             if (elem.RefName.Namespace == XmlSchema.Namespace)
  1428.             {
  1429.                 if (anyElement != null) return anyElement;
  1430.                 anyElement = new XmlSchemaElement ();
  1431.                 anyElement.Name = "any";
  1432.                 anyElement.SchemaTypeName = anyType;
  1433.                 return anyElement;
  1434.             }
  1435.             return (XmlSchemaElement) schemas.Find (elem.RefName, typeof(XmlSchemaElement));
  1436.         }
  1437.         
  1438.         XmlSchemaAttribute FindRefAttribute (XmlQualifiedName refName)
  1439.         {
  1440.             if (refName.Namespace == XmlSchema.Namespace)
  1441.             {
  1442.                 XmlSchemaAttribute at = new XmlSchemaAttribute ();
  1443.                 at.Name = refName.Name;
  1444.                 at.SchemaTypeName = new XmlQualifiedName ("string",XmlSchema.Namespace);
  1445.                 return at;
  1446.             }
  1447.             return (XmlSchemaAttribute) schemas.Find (refName, typeof(XmlSchemaAttribute));
  1448.         }
  1449.         
  1450.         void WriteRefTypeSample (XmlTextWriter xtw, string ns, XmlSchemaElement elem)
  1451.         {
  1452.             if (elem.SchemaTypeName.Namespace == XmlSchema.Namespace || schemas.Find (elem.SchemaTypeName, typeof(XmlSchemaSimpleType)) != null)
  1453.                 WriteElementSample (xtw, ns, elem);
  1454.             else
  1455.             {
  1456.                 xtw.WriteStartElement (elem.Name, ns);
  1457.                 xtw.WriteAttributeString ("href", "#id" + (queue.Count+1));
  1458.                 xtw.WriteEndElement ();
  1459.                 queue.Add (new EncodedType (ns, elem));
  1460.             }
  1461.         }
  1462.         
  1463.         void WriteQueuedTypeSamples (XmlTextWriter xtw)
  1464.         {
  1465.             for (int n=0; n<queue.Count; n++)
  1466.             {
  1467.                 EncodedType ec = (EncodedType) queue[n];
  1468.                 XmlSchemaComplexType st = FindComplexTyype (ec.Element.SchemaTypeName);
  1469.                 WriteComplexTypeSample (xtw, st, ec.Element.SchemaTypeName, n+1);
  1470.             }
  1471.         }
  1472.         
  1473.         XmlSchemaComplexType FindComplexTyype (XmlQualifiedName qname)
  1474.         {
  1475.             if (qname.Name.IndexOf ("[]") != -1)
  1476.             {
  1477.                 XmlSchemaComplexType stype = new XmlSchemaComplexType ();
  1478.                 stype.ContentModel = new XmlSchemaComplexContent ();
  1479.                 
  1480.                 XmlSchemaComplexContentRestriction res = new XmlSchemaComplexContentRestriction ();
  1481.                 stype.ContentModel.Content = res;
  1482.                 res.BaseTypeName = arrayType;
  1483.                 
  1484.                 XmlSchemaAttribute att = new XmlSchemaAttribute ();
  1485.                 att.RefName = arrayTypeRefName;
  1486.                 res.Attributes.Add (att);
  1487.                 
  1488.                 XmlAttribute xat = document.CreateAttribute ("arrayType", WsdlNamespace);
  1489.                 xat.Value = qname.Namespace + ":" + qname.Name;
  1490.                 att.UnhandledAttributes = new XmlAttribute[] {xat};
  1491.                 return stype;
  1492.             }
  1493.                 
  1494.             return (XmlSchemaComplexType) schemas.Find (qname, typeof(XmlSchemaComplexType));
  1495.         }
  1496.         
  1497.         string GetQualifiedNameString (XmlTextWriter xtw, XmlQualifiedName qname)
  1498.         {
  1499.             string pref = xtw.LookupPrefix (qname.Namespace);
  1500.             if (pref != null) return pref + ":" + qname.Name;
  1501.             
  1502.             xtw.WriteAttributeString ("xmlns", "q1", null, qname.Namespace);
  1503.             return "q1:" + qname.Name;
  1504.         }
  1505.                 
  1506.         protected virtual string GetLiteral (string s)
  1507.         {
  1508.             return s;
  1509.         }
  1510.  
  1511.         void GetOperationFormat (OperationBinding obin, out SoapBindingStyle style, out SoapBindingUse use)
  1512.         {
  1513.             style = SoapBindingStyle.Document;
  1514.             use = SoapBindingUse.Literal;
  1515.             SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
  1516.             if (sob != null) {
  1517.                 style = sob.Style;
  1518.                 SoapBodyBinding sbb = obin.Input.Extensions.Find (typeof(SoapBodyBinding)) as SoapBodyBinding;
  1519.                 if (sbb != null)
  1520.                     use = sbb.Use;
  1521.             }
  1522.         }
  1523.     }
  1524.  
  1525.  
  1526.  
  1527.  
  1528.  
  1529. </script>
  1530.  
  1531. <head>
  1532.     <link rel="alternate" type="text/xml" href="<%=Request.FilePath%>?disco"/>
  1533.  
  1534.     <title><%=WebServiceName%> Web Service</title>
  1535.     <style type="text/css">
  1536.         BODY { font-family: Arial; margin-left: 20px; margin-top: 20px; font-size: x-small}
  1537.         TABLE { font-size: x-small }
  1538.         .title { color:dimgray; font-family: Arial; font-size:20pt; font-weight:900}
  1539.         .operationTitle { color:dimgray; font-family: Arial; font-size:15pt; font-weight:900}
  1540.         .method { font-size: x-small }
  1541.         .bindingLabel { font-size: x-small; font-weight:bold; color:darkgray; line-height:8pt; display:block; margin-bottom:3px }
  1542.         .label { font-size: small; font-weight:bold; color:darkgray }
  1543.         .paramTable { font-size: x-small }
  1544.         .paramTable TR { background-color: gainsboro }
  1545.         .paramFormTable { font-size: x-small; padding: 10px; background-color: gainsboro }
  1546.         .paramFormTable TR { background-color: gainsboro }
  1547.         .paramInput { border: solid 1px gray }
  1548.         .button {border: solid 1px gray }
  1549.         .smallSeparator { height:3px; overflow:hidden }
  1550.         .panel { background-color:whitesmoke; border: solid 1px silver; border-top: solid 1px silver  }
  1551.         .codePanel { background-color: white; font-size:x-small; padding:7px; border:solid 1px silver}
  1552.         .code-xml { font-size:10pt; font-family:courier }
  1553.         .code-cs { font-size:10pt; font-family:courier }
  1554.         .code-vb { font-size:10pt; font-family:courier }
  1555.         .tabLabelOn { font-weight:bold }
  1556.         .tabLabelOff {color: darkgray }
  1557.         .literal-placeholder {color: darkblue; font-weight:bold}
  1558.         A:link { color: black; }
  1559.         A:visited { color: black; }
  1560.         A:active { color: black; }
  1561.         A:hover { color: blue }
  1562.     </style>
  1563.     
  1564. <script>
  1565. function clearForm ()
  1566. {
  1567.     document.getElementById("testFormResult").style.display="none";
  1568. }
  1569. </script>
  1570.  
  1571. </head>
  1572.  
  1573. <body>
  1574. <div class="title" style="margin-left:20px">
  1575. <span class="label">Web Service</span><br>
  1576. <%=WebServiceName%>
  1577. </div>
  1578.  
  1579. <!--
  1580.     **********************************************************
  1581.     Left panel
  1582. -->
  1583.  
  1584. <table border="0" width="100%" cellpadding="15px" cellspacing="15px">
  1585. <tr valign="top"><td width="150px" class="panel">
  1586. <div style="width:150px"></div>
  1587. <a class="method" href='<%=PageName%>'>Overview</a><br>
  1588. <div class="smallSeparator"></div>
  1589. <a class="method" href='<%=PageName + "?" + GetPageContext("wsdl")%>'>Service Description</a>
  1590. <div class="smallSeparator"></div>
  1591. <a class="method" href='<%=PageName + "?" + GetPageContext("proxy")%>'>Client proxy</a>
  1592. <br><br>
  1593.     <asp:repeater id="BindingsRepeater" runat=server>
  1594.         <itemtemplate name="itemtemplate">
  1595.             <span class="bindingLabel"><%#FormatBindingName(DataBinder.Eval(Container.DataItem, "Name").ToString())%></span>
  1596.             <asp:repeater id="OperationsRepeater" runat=server datasource='<%# ((Binding)Container.DataItem).Operations %>'>
  1597.                 <itemtemplate>
  1598.                     <a class="method" href="<%=PageName%>?<%=GetTabContext("op",null)%>op=<%#GetOpName(Container.DataItem)%>&bnd=<%#DataBinder.Eval(Container.DataItem, "Binding.Name")%>"><%#GetOpName(Container.DataItem)%></a>
  1599.                     <div class="smallSeparator"></div>
  1600.                 </itemtemplate>
  1601.             </asp:repeater>
  1602.             <br>
  1603.         </itemtemplate>
  1604.     </asp:repeater>
  1605.  
  1606. </td><td class="panel">
  1607.  
  1608. <% if (CurrentPage == "main") {%>
  1609.  
  1610. <!--
  1611.     **********************************************************
  1612.     Web service overview
  1613. -->
  1614.  
  1615.     <p class="label">Web Service Overview</p>
  1616.     <%=WebServiceDescription%>
  1617.     
  1618. <%} if (DefaultBinding == null) {%>
  1619. This service does not contain any public web method.
  1620. <%} else if (CurrentPage == "op") {%>
  1621.  
  1622. <!--
  1623.     **********************************************************
  1624.     Operation description
  1625. -->
  1626.  
  1627.     <span class="operationTitle"><%=CurrentOperationName%></span>
  1628.     <br><br>
  1629.     <% WriteTabs (); %>
  1630.     <br><br><br>
  1631.     
  1632.     <% if (CurrentTab == "main") { %>
  1633.         <span class="label">Input Parameters</span>
  1634.         <div class="smallSeparator"></div>
  1635.         <% if (InParams.Count == 0) { %>
  1636.             No input parameters<br>
  1637.         <% } else { %>
  1638.             <table class="paramTable" cellspacing="1" cellpadding="5">
  1639.             <asp:repeater id="InputParamsRepeater" runat=server>
  1640.                 <itemtemplate>
  1641.                     <tr>
  1642.                     <td width="150"><%#DataBinder.Eval(Container.DataItem, "Name")%></td>
  1643.                     <td width="150"><%#DataBinder.Eval(Container.DataItem, "Type")%></td>
  1644.                     </tr>
  1645.                 </itemtemplate>
  1646.             </asp:repeater>
  1647.             </table>
  1648.         <% } %>
  1649.         <br>
  1650.         
  1651.         <% if (OutParams.Count > 0) { %>
  1652.         <span class="label">Output Parameters</span>
  1653.             <div class="smallSeparator"></div>
  1654.             <table class="paramTable" cellspacing="1" cellpadding="5">
  1655.             <asp:repeater id="OutputParamsRepeater" runat=server>
  1656.                 <itemtemplate>
  1657.                     <tr>
  1658.                     <td width="150"><%#DataBinder.Eval(Container.DataItem, "Name")%></td>
  1659.                     <td width="150"><%#DataBinder.Eval(Container.DataItem, "Type")%></td>
  1660.                     </tr>
  1661.                 </itemtemplate>
  1662.             </asp:repeater>
  1663.             </table>
  1664.         <br>
  1665.         <% } %>
  1666.         
  1667.         <span class="label">Remarks</span>
  1668.         <div class="smallSeparator"></div>
  1669.         <%=OperationDocumentation%>
  1670.         <br><br>
  1671.         <span class="label">Technical information</span>
  1672.         <div class="smallSeparator"></div>
  1673.         Format: <%=CurrentOperationFormat%>
  1674.         <br>Supported protocols: <%=CurrentOperationProtocols%>
  1675.     <% } %>
  1676.     
  1677. <!--
  1678.     **********************************************************
  1679.     Operation description - Test form
  1680. -->
  1681.  
  1682.     <% if (CurrentTab == "test") { 
  1683.         if (CurrentOperationSupportsTest) {%>
  1684.             Enter values for the parameters and click the 'Invoke' button to test this method:<br><br>
  1685.             <form action="<%=PageName%>" method="GET">
  1686.             <input type="hidden" name="page" value="<%=CurrentPage%>">
  1687.             <input type="hidden" name="tab" value="<%=CurrentTab%>">
  1688.             <input type="hidden" name="op" value="<%=CurrentOperationName%>">
  1689.             <input type="hidden" name="bnd" value="<%=CurrentOperationBinding%>">
  1690.             <input type="hidden" name="ext" value="testform">
  1691.             <table class="paramFormTable" cellspacing="0" cellpadding="3">
  1692.             <asp:repeater id="InputFormParamsRepeater" runat=server>
  1693.                 <itemtemplate>
  1694.                     <tr>
  1695.                     <td><%#DataBinder.Eval(Container.DataItem, "Name")%>: </td>
  1696.                     <td width="150"><input class="paramInput" type="text" size="20" name="<%#DataBinder.Eval(Container.DataItem, "Name")%>"></td>
  1697.                     </tr>
  1698.                 </itemtemplate>
  1699.             </asp:repeater>
  1700.             <tr><td></td><td><input class="button" type="submit" value="Invoke"> <input class="button" type="button" onclick="clearForm()" value="Clear"></td></tr>
  1701.             </table>
  1702.             </form>
  1703.             <div id="testFormResult" style="display:<%= (HasFormResult?"block":"none") %>">
  1704.             The web service returned the following result:<br/><br/>
  1705.             <div class="codePanel"><%=GetTestResult()%></div>
  1706.             </div>
  1707.         <% } else {%>
  1708.         The test form is not available for this operation because it has parameters with a complex structure.
  1709.         <% } %>
  1710.     <% } %>
  1711.     
  1712. <!--
  1713.     **********************************************************
  1714.     Operation description - Message Layout
  1715. -->
  1716.  
  1717.     <% if (CurrentTab == "msg") { %>
  1718.         
  1719.         The following are sample SOAP requests and responses for each protocol supported by this method:
  1720.             <br/><br/>
  1721.         
  1722.         <% if (IsOperationSupported ("Soap")) { %>
  1723.             <span class="label">Soap</span>
  1724.             <br/><br/>
  1725.             <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("Soap", true)%></div></div>
  1726.             <br/>
  1727.             <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("Soap", false)%></div></div>
  1728.             <br/>
  1729.         <% } %>
  1730.         <% if (IsOperationSupported ("HttpGet")) { %>
  1731.             <span class="label">HTTP Get</span>
  1732.             <br/><br/>
  1733.             <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("HttpGet", true)%></div></div>
  1734.             <br/>
  1735.             <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("HttpGet", false)%></div></div>
  1736.             <br/>
  1737.         <% } %>
  1738.         <% if (IsOperationSupported ("HttpPost")) { %>
  1739.             <span class="label">HTTP Post</span>
  1740.             <br/><br/>
  1741.             <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("HttpPost", true)%></div></div>
  1742.             <br/>
  1743.             <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("HttpPost", false)%></div></div>
  1744.             <br/>
  1745.         <% } %>
  1746.         
  1747.     <% } %>
  1748. <%} else if (CurrentPage == "proxy") {%>
  1749. <!--
  1750.     **********************************************************
  1751.     Client Proxy
  1752. -->
  1753.     <form action="<%=PageName%>" name="langForm" method="GET">
  1754.         Select the language for which you want to generate a proxy 
  1755.         <input type="hidden" name="page" value="<%=CurrentPage%>"> 
  1756.         <SELECT name="lang" onchange="langForm.submit()">
  1757.             <%=GetOptionSel("cs",CurrentLanguage)%>C#</option>
  1758.             <%=GetOptionSel("vb",CurrentLanguage)%>Visual Basic</option>
  1759.         </SELECT>
  1760.           
  1761.     </form>
  1762.     <br>
  1763.     <span class="label"><%=CurrentProxytName%></span>   
  1764.     <a href="<%=PageName + "?code=" + CurrentLanguage%>">Download</a>
  1765.     <br><br>
  1766.     <div class="codePanel">
  1767.     <div class="code-<%=CurrentLanguage%>"><%=GetProxyCode ()%></div>
  1768.     </div>
  1769. <%} else if (CurrentPage == "wsdl") {%>
  1770. <!--
  1771.     **********************************************************
  1772.     Service description
  1773. -->
  1774.     <% if (descriptions.Count > 1 || schemas.Count > 1) {%>
  1775.     The description of this web service is composed by several documents. Click on the document you want to see:
  1776.     
  1777.     <ul>
  1778.     <% 
  1779.         for (int n=0; n<descriptions.Count; n++)
  1780.             Response.Write ("<li><a href='" + PageName + "?" + GetPageContext(null) + "doctype=wsdl&docind=" + n + "'>WSDL document " + descriptions[n].TargetNamespace + "</a></li>");
  1781.         for (int n=0; n<schemas.Count; n++)
  1782.             Response.Write ("<li><a href='" + PageName + "?" + GetPageContext(null) + "doctype=schema&docind=" + n + "'>Xml Schema " + schemas[n].TargetNamespace + "</a></li>");
  1783.     %>
  1784.     </ul>
  1785.     
  1786.     <%} else {%>
  1787.     <%}%>
  1788.     <br>
  1789.     <span class="label"><%=CurrentDocumentName%></span>   
  1790.     <a href="<%=PageName + "?" + CurrentDocType + "=" + CurrentDocInd %>">Download</a>
  1791.     <br><br>
  1792.     <div class="codePanel">
  1793.     <div class="code-xml"><%=GenerateDocument ()%></div>
  1794.     </div>
  1795.  
  1796. <%}%>
  1797.  
  1798. <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
  1799. </td>
  1800. <td width="20px"></td>
  1801. </tr>
  1802.  
  1803. </table>
  1804. </body>
  1805. </html>
  1806.